package rmi;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.*;
import java.util.ArrayList;
import java.net.*;

public class RmiClient
{
	 static public void main(String args[])
	    {
	       ReceiveMessageInterface rmiServer;
	       Registry registry;
	       String serverAddress=args[0];
	       String serverPort=args[1];
	       String text=args[2];
	       int[] myIntArray = {1,2,3};
	       ArrayList<String> stringArray = new ArrayList<String>();
	       stringArray.add("isto ");
	       stringArray.add("esta ");
	       stringArray.add("a funcionar");
	       
	       Container container = new Container(5,"ola",myIntArray,stringArray);
	       System.out.println("sending "+text+" to "+serverAddress+":"+serverPort);
	       try{
	           // get the �gregistry�h
	           registry=LocateRegistry.getRegistry(
	               serverAddress,
	               (new Integer(serverPort)).intValue()
	           );
	           // look up the remote object
	           rmiServer=
	              (ReceiveMessageInterface)(registry.lookup("rmiServer"));
	           // call the remote method
	           rmiServer.receiveMessage(text);
	           rmiServer.receiveContainer(container);
	       }
	       catch(RemoteException e){
	           e.printStackTrace();
	       }
	       catch(NotBoundException e){
	           e.printStackTrace();
	       }
	    }
}
